package 队列.数组模拟队列;
/*
* 数组模拟队列 -> 尾进头出
* */


public class Queue {
    private int capacity;// 队列容量
    private int front = -1;// 队列头部
    private int rear = -1;// 队列尾部
    private int[] arr = new int[capacity];

    public Queue(int capacity){
        this.capacity = capacity;
    }

    // 入队列
    public void addQueue(int data) throws Exception {
        if(IsFull()){
            throw new RuntimeException("队列已满,无法插入新的数据");
        }
        arr[++rear] = data;
    }
    /*
    * 出队列,显示队头元素,显示队列在此处不在写,思路相同;
    * */

    public void getQueue(){
        if(IsEmpty()){
            throw new RuntimeException("队列为空,无法出队列!");
        }
        front++;// front 后移
    }


    // 判断队列是否已满
    private Boolean IsFull(){
        return rear == capacity-1;
    }

    // 判断队列是否为空
    private Boolean IsEmpty(){
        return rear == front;
    }

}
